using System;
using InfoJetSoft.Service.Worker;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.ManagedCode
{
	/// <summary>
	/// Summary description for Submit2HostAdapter.
	/// </summary>
	public class Submit2HostAdapter
	{
		private InfoJetSoft.Service.Entity.Form form = null;
		private InfoJetSoft.Service.Entity.SubmitToHostAdapter submitToHostAdapter = null;

		public Submit2HostAdapter( InfoJetSoft.Service.Entity.Form frm, InfoJetSoft.Service.Entity.SubmitToHostAdapter hostAdapter )
		{
			this.form = frm;
			this.submitToHostAdapter = (InfoJetSoft.Service.Entity.SubmitToHostAdapter)DataAdapterTableUtil.getCurrentAdapter( this.form, hostAdapter );
		}

		public string Name 
		{ 
			get
			{
				return this.submitToHostAdapter.Name;
			}
		}


		public bool QueryAllowed 
		{ 
			get
			{
				return this.submitToHostAdapter.QueryAllowed;
			}
		}

		public bool SubmitAllowed 
		{ 
			get
			{
				return this.submitToHostAdapter.SubmitAllowed;
			}
		}

		public void Submit()
        {
            //CID 0859 //2012.03.19 //Begin
            int errorCount = FormIsValidateWorker.Validate(form);
            if (errorCount > 0)
            {
                throw new InfoJetException(MessageUtil.FormContainsValidationErrors(), null);
            }
            //CID 0859 //2012.03.19 //End
			SubmitToHostWorker.submitDoc( this.form, this.submitToHostAdapter );
		}
		
		//Unsupported
		public void Query(){}

	}
}
